package com.example.clxy.controller;

import com.example.clxy.entity.dto.RegDto;
import com.example.clxy.interceptor.AppToken;
import com.example.clxy.result.PageResult;
import com.example.clxy.result.WebRestResult;
import com.example.clxy.result.business.PageResult.StudentScorePageResult;
import com.example.clxy.result.business.RegResult;
import com.example.clxy.result.business.StudentScoreResult;
import com.example.clxy.service.ScoreService;
import com.itextpdf.text.DocumentException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @author weichong
 * date 2020-08-05
 * @Description:
 */
@AppToken
@RestController
@RequestMapping("ScoreController")
@CrossOrigin
public class ScoreController {

    @Autowired
    private ScoreService scoreService;

    /**
     * 实验卡/预习报告/实验报告打分
     *
     * @param scheduleid
     * @param studentid
     * @param yxscore
     * @param sykscore
     * @param sybgscore
     * @return
     */
    @RequestMapping("updateScore")
    public WebRestResult updateScore(String scheduleid, String studentid, Double yxscore, Double sykscore, Double sybgscore, String yxscorereason, String sykscorereason, String sybgscoreason, Double sygfxscore, Double sbwhscore, Double xczlscore) {
        WebRestResult res = scoreService.updateScore(scheduleid, studentid, yxscore, sykscore, sybgscore, yxscorereason, sykscorereason, sybgscoreason, sygfxscore, sbwhscore, xczlscore);
        return res;
    }

    @RequestMapping("getStudentScoreBySchedule")
    public PageResult<StudentScorePageResult> getStudentScoreBySchedule(String scheduleid, String wlclassid, String studentname, String wlclassname, int page, int pagesize) {
        PageResult<StudentScorePageResult> res = scoreService.getStudentScoreBySchedule(scheduleid, wlclassid, studentname, wlclassname, page, pagesize);
        return res;
    }

    @RequestMapping("getStudentScoreByStudent")
    public PageResult<StudentScorePageResult> getStudentScoreByStudent(String studentid, String scheduleid, String semesterid, int page, int pagesize) {
        PageResult<StudentScorePageResult> res = scoreService.getStudentScoreByStudent(studentid, scheduleid, semesterid, page, pagesize);
        return res;
    }

    @PostMapping("mergePdfFilesByStudent")
    public StudentScoreResult mergePdfFilesByStudent(String scheduleid, String studentid) throws IOException, DocumentException {
        StudentScoreResult result = scoreService.mergePdfFilesByStudent(scheduleid, studentid);
        return result;
    }

    /**
     * 管理员更新规格化分数
     */
    @PostMapping("updateReg")
    public WebRestResult updateReg(String dictid,String regscore) {
        WebRestResult result = scoreService.updateReg(dictid,regscore);
        return result;
    }

    /**
     * 管理员更新规格化分数
     */
    @PostMapping("updateReg1")
    public WebRestResult updateReg1(@RequestBody RegDto regDto) {
        WebRestResult result = scoreService.updateReg1(regDto);
        return result;
    }


    /**
     * 查看规格化分数
     */
    @GetMapping("getRegList")
    public RegResult getRegList() {
        RegResult result = scoreService.getRegList();
        return result;
    }


}
